package io.gitee.skyarthur1987.leporidae.delayqueue.biz;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.gitee.skyarthur1987.leporidae.delayqueue.api.DelayQueuePollEventHandler;
import io.gitee.skyarthur1987.leporidae.delayqueue.core.DelayQueuePollEvent;
import io.gitee.skyarthur1987.leporidae.utils.base.JsonUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * Created by skyarthur on 2023/1/29
 */
@Service
public class EventCollectTestHandler implements DelayQueuePollEventHandler {
    public static final List<TaskDto> TASKS = Lists.newArrayList();

    @Override
    public void handle(DelayQueuePollEvent pollEvent) {
        TASKS.addAll(pollEvent.getTask().getTasks().stream()
                .map(x -> JsonUtils.fromJson(x, TaskDto.class)).toList());
    }

    @Override
    public Set<String> getSupportedTopics() {
        return Sets.newHashSet(DelayQueueTopic.TASK_PRINT.getTopic());
    }
}
